|
|
|
|
|
|
|
This became the following: |
|
|
|
|
|
|
|
|
Private Const UF_NORMAL_ACCOUNT = &H200 |
|
|
|
|
|
|
|
|
Note that the value is in hexadecimal. |
|
|
|
|
|
|
|
|
A quick read of the documentation suggested that all of the other parameters could be 0. My first test used the following code: |
|
|
|
|
|
|
|
|
Private Sub Command1_Click()
Dim ul2 As USER_INFO_2
Dim res As Long
Dim parm_err As Long
ul2.usri2_name = StrPtr("puzzle" & chr$(0))
ul2.usri2_password = StrPtr("pass" & chr$(0))
ul2.usri2_priv = USER_PRIV_USER
res = NetUserAdd(O, 2, VarPtr(ul2), parm_err)
Debug.Print "Result: " & res
If res <> 0 Then Debug.Print "Error at index: " & parm_err
End Sub |
|
|
|
|
|
|
|
|
What is that nasty trick I pulled with the usri2_name and usri2_password parameters? In the structure, I defined them as Longs and as requiring a pointer to a NULL-terminated Unicode string. The StrPtr operator returns a pointer to the internal string data of a Visual Basic string, and we know that Visual Basic stores data internally in Unicode. This is especially safe because these string parameters are read-onlythe NetUserAdd API function never changes the data in these strings. |
|
|
|
|
|
|
|
|
It was finally time to find out what would happen when I ran the program. |
|
|
|
|
|
|
|
|
The result displayed by the Debug.Print statement indicated error 87, with the error at index 8. |
|
|
|
|
|
|
|
|
I was curious what error 87 was. Since this is an API function, I could use the FormatMessage function to retrieve a text description of the error (as you've seen in the GetErrorString function, used in many places in this book). But in this case I was lazy, so I just did a search for ERROR_ in the api32.txt file on the CDROM that comes with this book. After finding the first constant in the error list, ERROR_SUCCESS, I searched down for number 87 and found the constant ERROR_INVALID_PARAMETER. I should have realized that would be the errorthe SDK documentation mentioned that the parm_err parameter would only be set if a parameter was invalid. Which field is number 8? It's either usri2_script_path or usri2_auth_flags, depending on whether the first parameter is considered 0 or 1. Neither of these makes any sense. The usri2_script_path parameter is clearly documented as accepting a NULL string. The |
|
|
|
|
|